<?php

namespace App\Http\Middleware;


use App\Framework\Model\ManagerModule;
use App\Framework\Model\Message;
use App\Framework\Session\ManagerSession;
use Closure;
use Illuminate\Support\Facades\URL;

class ManagerPower
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next, $moduleID,$permissionID)
    {
        if (!ManagerSession::hasPermission($moduleID, $permissionID)) {
            if ($request->ajax()) {
                $msg = Message::setFalse('权限不足');
                return response()->json($msg);
            } else {
                return redirect(URL::action('CommonController@noPower'));
            }
        }

        return $next($request);
    }
}
